﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class PopWin_personal : System.Web.UI.Page
{
    PM.Model.Sys_Account teacher = null;
    PM.PMSys.account account = new PM.PMSys.account();
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            if (Session["tid"] != null)
            {
                teacher = new PM.Model.Sys_Account();
                bindddl();
                teacher = account.GetModel(Session["tid"].ToString());
                if (teacher != null)
                    setModel(teacher);
                else
                    PM.Code.Web.alertmessage.ShowMsg("抱歉，获取信息失败！请重试");
            }
            else
                Response.Redirect("../Error/Error.htm");
        }
    }
    //绑定学院
    protected void bindddl()
    {
        PM.Code.Web.controlbind.BindDropDownList(this.ddlCollege, "select collegename from Dict_College", "collegename", "collegename");
    }
    //添加数据
    public void setModel(PM.Model.Sys_Account myself)
    {
        this.labID.Text = myself.tid;
        this.txtname.Text = myself.name;
        if (myself.sex == "男")
            this.radsex1.Checked = true;
        else
            this.radsex2.Checked = true;
        this.ddlCollege.SelectedValue = myself.depart.Trim();
        this.txtfield.Text = myself.field;
        this.ddlbg.SelectedValue = myself.bg.Trim();
        this.ddltitle.SelectedValue = myself.title.Trim();
        this.txttel.Text = myself.telephone;
        this.txtcell.Text = myself.cellphone;
        this.txtemail.Text = myself.email;
        this.txtremark.Text = myself.intro;
    }

    protected void btnSubmit_Click(object sender, EventArgs e)
    {
        if (Check())
            updateInfo();
    }

    protected bool Check()
    {
        if (this.txtname.Text.Trim() == string.Empty)
        {
            PM.Code.Web.alertmessage.ShowMsg("姓名不能为空！");
            return false;
        }
        else if (!this.radsex1.Checked && !this.radsex2.Checked)
        {
            PM.Code.Web.alertmessage.ShowMsg("请选择性别！");
            return false;
        }
        else if (this.txtfield.Text.Trim() == string.Empty)
        {
            PM.Code.Web.alertmessage.ShowMsg("姓名不能为空！");
            return false;
        }
        else if (this.txtcell.Text.Trim() == string.Empty)
        {
            PM.Code.Web.alertmessage.ShowMsg("手机不能为空！");
            return false;
        }
        else if (this.txtemail.Text.Trim() == string.Empty)
        {
            PM.Code.Web.alertmessage.ShowMsg("电子信箱不能为空！");
            return false;
        }
        else
            return true;
    }

    protected void updateInfo()
    {
        teacher = new PM.Model.Sys_Account();
        teacher.tid = this.labID.Text.Trim();
        teacher.name = this.txtname.Text.Trim();
        if (this.radsex1.Checked)
            teacher.sex = "男";
        else
            teacher.sex = "女";
        teacher.depart = this.ddlCollege.SelectedValue.Trim();
        teacher.field = this.txtfield.Text.Trim();
        teacher.bg = this.ddlbg.SelectedValue.Trim();
        teacher.title = this.ddltitle.SelectedValue.Trim();
        teacher.telephone = this.txttel.Text.Trim();
        teacher.cellphone = this.txtcell.Text.Trim();
        teacher.email = this.txtemail.Text.Trim();
        teacher.intro = this.txtremark.Text.Trim();
        int result = account.UpdateAccount(teacher);
        if (result == 1)
            this.note.InnerHtml = "<img src=\"../js/themes/icons/ok.png\" alt=\"提示\" /><span>您的信息修改成功！</span>";
        else
            this.note.InnerHtml = "<img src=\"../js/themes/icons/no.png\" alt=\"提示\" /><span>您的信息修改失败！</span>";
        this.btnSubmit.Enabled = false;
    }
}
